require(['config'], function () {
    require(['jquery'], function () {
        require(['lazy','jqcookie'], function () {
            (function () {
                const phpurl = 'http://10.31.155.19/MallProject/php/';
                let navA = $('.header2-nav-l dl');
                let unbanner = $('.wel-intro ul');
                let falshsale = $('.wel-limit-list');
                let hotsale = $('.bursting ul');
                let F1 = $('.f1-ajax .right');
                let F2 = $('.f2-ajax .right');
                let video = $('.wel-video .wel-video-list');
                let details = $('.main .inner .shopping-show .shopping-list ul');
                let descriptiontitle = $('.main .inner .shopping-description h3');
                let descriptionp = $('.main .inner .shopping-description p');
                let price = $('.main .inner .shopping-description .promotion .promotion-price');
                let goodlist = $('.main .inner .shopping-description .typesof .ajaxShowSkus .colortype .modnum');
                let title = $('.navshow .inner');
                $.when($.ajax({
                    url: phpurl + 'hnav.php',
                    dataType: 'json'
                }), $.ajax({
                    url: phpurl + 'unbanner.php',
                    dataType: 'json'
                }), $.ajax({
                    url: phpurl + 'falshsale.php',
                    dataType: 'json'
                }), $.ajax({
                    url: phpurl + 'hotsale.php',
                    dataType: 'json'
                }), $.ajax({
                    url: phpurl + 'f1.php',
                    dataType: 'json'
                }), $.ajax({
                    url: phpurl + 'video.php',
                    dataType: 'json'
                })).done(function (bossdata, unbannerdata, fsaledata, hsaledata, f1data, videodata) {

                    //全部商品下拉菜单
                    let strhtml = '';
                    for (let value of bossdata[0]) {
                        strhtml += `
                            <dd><a>
                            <img data-original="${value.url}" class="lazy" width="60" height="30">
                            <p>${value.title}</p>
                            </a></dd>
                            `;
                    }
                    strhtml += '';
                    navA.html(strhtml);

                    //轮播图下列表
                    strhtml = '';
                    for (let value of unbannerdata[0]) {
                        strhtml += `
                            <li>
                            <a href="" target="_blank">
                            <img data-original="${value.url}" class="lazy" width="295" height="160">
                            <p>${value.title}</p>
                            </a>
                            </li>
                        `;
                    }
                    strhtml += '';
                    unbanner.html(strhtml);

                    //限时优惠---------
                    strhtml = '';
                    for (let value of fsaledata[0]) {
                        strhtml += `
                        <li class="productTab">
                            <a href="details.html?falshsale=${value.sid}">
                                <div class="pic fl">
                                    <img data-original="${value.url}" alt="" class="lazy" width="220" height="220">
                                </div>
                                <div class="con fr">
                                    <h2>${value.title}</h2>
                                    <p>${value.details}</p>
                                    <div class="money">特惠价:￥
                                        <span class="yuan">${value.price}</span>
                                    </div>
                                    <div class="more">立即购买</div>
                                </div>
                            </a>
                        </li>
                        `;
                    }
                    strhtml += '';
                    falshsale.html(strhtml);

                    //爆款特卖
                    strhtml = '';
                    for (let value of hsaledata[0]) {
                        strhtml += `
                        <li>
                        <div class="bt">
                            <span class="red">${value.discounts}</span>
                        </div>
                        <div class="pic productTab">
                            <a href="details.html?hotsale=${value.sid}">
                                <img data-original="${value.url}" alt="" class="img lazy" width="220" height="220">
                                <div class="er-box f-cb">
                                    <h2>${value.remake}</h2>
                                    <p>${value.remakefrom}</p>
                                </div>
                            </a>
                        </div>
                        <div class="con">
                            <a href="">
                                <h2>${value.title}</h2>
                                <p>${value.details}</p>
                                <div class="tt opsen">
                                    ￥<span class="money">${value.price}</span>
                                    <span class="jf f-cb">
                                        <i></i>
                                        ${value.int}
                                    </span>
                                </div>
                                <div class="tt">
                                    ￥<span class="money">3899.00</span>
                                    <span class="jf f-cb">
                                        <i></i>
                                        ${value.int}
                                    </span>
                                </div>
                            </a>
                            <div class="btns">
                                <a href="" class="info">查看详情</a>
                                <a href="" class="have">咨询有礼</a>
                            </div>
                        </div>
                    </li>
                        `;
                    }
                    strhtml += '';
                    hotsale.html(strhtml);

                    //F1，F2------------------------------------------
                    let k = 0;
                    for (let j = 0; j < F1.length; j++) {
                        let strhtml1 = '';
                        for (let i = 0; i < 4; i++) {
                            strhtml1 += `
                            <li class="productTab one">
                                        <a href="details.html?f1=${i + k+1}">
                                            <div class="bt">
                                                <span class="red">立减300元</span>
                                            </div>
                                            <div class="pic fl">
                                                <img data-original="${f1data[0][i + k].url}" alt="" class="lazy" width="180" height="180">
                                            </div>
                                            <div class="con fr">
                                                <h2>${f1data[0][i + k].title}</h2>
                                                <p>${f1data[0][i + k].modnum}</p>
                                                <p>${f1data[0][i + k].details}</p>
                                                <div class="money">
                                                    <span class="y">￥</span>
                                                    ${f1data[0][i + k].price}
                                                </div>
                                                <div class="jf">
                                                    <i></i>
                                                    赠送${f1data[0][i + k].price}积分
                                                </div>
                                                <span class="bbts">咨询有礼</span>
                                            </div>
                                        </a>
                                    </li>
                            `;
                            strhtml1 += '';
                            F1.eq(j).html(strhtml1);
                            F2.eq(j).html(strhtml1);
                        }
                        k += 4;
                    }

                    //视频-------------------------------------
                    strhtml = '';
                    for (let value of videodata[0]) {
                        strhtml += `
                        <li data-url="https://img.shoprobam.com/Public/video/40th_foryou.swf" str="40年更懂你"><a
                            href="javascript:void()" data-url="https://img.shoprobam.com/Public/video/40th_foryou.swf"
                            str="40年更懂你">
                            <div class="pic"><img 
                                    alt="" class="lazy"
                                    data-original="${value.url}"
                                    style="width: 295px; height: 180px; display: inline;"><span class="bg"></span><span
                                    class="open"></span></div>
                            <div class="con">
                                <h2>${value.title}</h2>
                                <p>${value.titles}</p>
                            </div>
                        </a></li>
                    </li>
                        `;
                    }
                    strhtml += '';
                    video.html(strhtml);
                    $(function () { //页面加载完成
                        $("img.lazy").lazyload({
                            effect: "fadeIn" //效果方式
                        });
                    });

                    //详情页
                    strhtml = '';
                    
                    let i = location.search.substring(1).split('=')[1]-1;
                    if(!i){
                        i=0;
                    }
                    for (let value of fsaledata[0][i].urls.split(',')) {
                        strhtml += `
                        <li style="cursor: pointer;">
                            <img src="${value}" width="100%">
                        </li>
                        `;
                    }
                    details.html(strhtml);
                    strhtml = '';
                    strhtml += `${fsaledata[0][i].title}`;
                    descriptiontitle.html(strhtml);
                    strhtml = '';
                    strhtml += `
                    <a href="/Home/Index/index">首页</a>
                    <span>&gt;</span>
                    <a href="/Home/Products/index">全部商品</a>
                    <span>&gt;</span>
                    <a href="/Home/Products/detail/gid/1459">${fsaledata[0][i].title}【新品上市】</a>
                    `;
                    title.html(strhtml);
                    strhtml='';
                    strhtml = `
                            ${fsaledata[0][i].description.split(',')[0]}<br>
                            ${fsaledata[0][i].description.split(',')[1]}<br>
                            ${fsaledata[0][i].description.split(',')[2]}<br>
                            ${fsaledata[0][i].description.split(',')[3]}<br>
                            ${fsaledata[0][i].description.split(',')[4]}
                    `;
                    descriptionp.html(strhtml);
                    strhtml = '';
                    strhtml += `
                    <div class="presaleHide"><span class="price-text">价格</span>
                                <input type="hidden" id="pmn_active_price" value="0">
                                <span class="price" id="showPrice"><i>￥</i>${fsaledata[0][i].price}</span>
                            </div>
                            <div class="promotion-price" id="GetLastP" style="">
                                <span class="price-text">到手价</span>
                                <span class="price" style="font-size:14px; padding-left:5px;">
                                    <i>￥</i>
                                    <label id="lastPrice">${fsaledata[0][i].saleprice}</label>
                                </span>
                            </div>
                    `;
                    price.html(strhtml);
                    strhtml='';
                    for(let value of fsaledata[0][i].modnum.split(',')){
                        strhtml += `
                            <a href="javascript:;">
                                <span name="${value}">
                                    ${value}
                                </span>
                            </a>
                    `;
                    }
                    goodlist.html(strhtml);
                });
            })()
        });
    });
});